using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using Text = TMPro.TMP_Text;

public class PopupTipManager : MonoSingleton<PopupTipManager> {
	public SimplePopupTextRoot textRoot;
	public Text textPrefab;
	public UIGainItemTip gainItemTipPrefab;
	public float textInterval;

	private Dictionary<string, float> m_tipHash = new();

	public void Start() {
		//Debug.Log(TilemapDataManager.Instance.GetMon3trWalkableDir(Vector3Int.zero));
	}

	public void ShowTextTip(string content) {
		var last = m_tipHash.GetValueOrDefault(content, 0);
		if (Time.time - last < textInterval) {
			return;
		}
		m_tipHash[content] = Time.time;
		var textInst = Instantiate(textPrefab);
		textInst.text = content;
		var tween = textInst.gameObject.FadeUIObjViaCanvasGroup(1);
		tween.SetDelay(1);

		textRoot.AddPopup(textInst.transform as RectTransform);
	}

	public void ShowGainItem(ItemId itemId, int cnt) {
		Debug.Log(itemId.ToString());
		var sprite = BattleFlowController.Instance.LoadIcon(itemId.ToString());
		var name = itemId.ToString();

		var tip = Instantiate(gainItemTipPrefab);
		tip.Render(sprite, name, cnt);
		var tween = tip.gameObject.FadeUIObjViaCanvasGroup(1);
		tween.SetDelay(1);

		textRoot.AddPopup(tip.transform as RectTransform);
	}
}
